package com.ssh.biz.impl;

import java.util.List;


import org.springframework.stereotype.Service;


import com.ssh.biz.IPetinfoBiz;
import com.ssh.dao.BaseDao;
import com.ssh.entity.Petinfo;;
@Service
public class PetinfoBizImpl extends BaseDao<Petinfo> implements IPetinfoBiz {

	public void delPet(Petinfo petinfo) {
		this.delete(petinfo);
	}


	public List<Petinfo> findAllPet() {
		return this.findAll();
	}

	public Petinfo findPetByID(Integer petId) {
		return this.find(petId);
	}

	public void savePet(Petinfo petinfo) {
		this.save(petinfo);

	}

	public void updatePet(Petinfo petinfo) {
		this.update(petinfo);

	}


	public List<Petinfo> findPetByName(String petName) {
		// TODO Auto-generated method stub
		return super.findAll("petName=?", new Object[]{petName});
	}


	public List<Petinfo> findPetinfoByAny(String petName, String petOwnerName,String petType) 
	{
		StringBuffer where = new StringBuffer();
		where.append("select pet from Petinfo pet where 1=1 ");
		if(petName!=null || petOwnerName!=null || petType!=null)
		{
			if(!petName.equals("") || petName != null){
				where.append(" and pet.petName like '%"+petName+"%'");
			}
		if(!petOwnerName.equals("") || petOwnerName!=null){
				where.append(" and pet.petOwnerName like '%"+petOwnerName+"%'");
			}
		if(Integer.parseInt(petType) > 0){
				where.append(" and pet.petType="+Integer.parseInt(petType));
			}
//		if(listType.length()>0){
//		where.append(" and pet.listType="+listType);
//	}
		}


			
			
		return this.findAll(where.toString());
	}

	
}
	
		
	
